package 字母异位词分组49;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
 * @author 谢阳
 * @version 1.8.0_131
 */
class Solution {
    public static void main(String[] args) {
        String[] str = {"eat","tea","tan","ate","nat","bat"};
        List<List<String>> lists = groupAnagrams(str);

    }
    public static List<List<String>> groupAnagrams(String[] strs) {
        HashMap<String, List<String>> hashMap = new HashMap<>();
        for (String str : strs) {
            char[] chars = str.toCharArray();
            Arrays.sort(chars);
            String key = new String(chars);
            System.out.println(key);
            if (!hashMap.containsKey(key)) {
                hashMap.put(key,new ArrayList<String>());
            }
            hashMap.get(key).add(str);
        }
        return new ArrayList(hashMap.values());
    }
}